package com.xtck.ha.fault.modules.controller;


import com.xtck.ha.fault.framework.page.PageResult;
import com.xtck.ha.fault.framework.utils.JsonResult;
import com.xtck.ha.fault.modules.convert.FmeaInfoConvert;
import com.xtck.ha.fault.modules.pojo.dto.FmeaInfoDTO;
import com.xtck.ha.fault.modules.pojo.entity.FmeaInfo;
import com.xtck.ha.fault.modules.pojo.vo.FmeaInfoVO;
import com.xtck.ha.fault.modules.service.FmeaInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
*  controller
*
* @ClassName: FmeaInfoController
* @Description: 控制层访问接口
* @author liuyuan
* @date 2025-06-17
*/
@RestController
@RequestMapping("/fmeaInfo1")
@Api(tags={"故障信息接口管理"})
public class FmeaInfoController  {
    @Autowired
    private FmeaInfoService fmeaInfoService;

    public  FmeaInfoService getService() {
        return fmeaInfoService;
    }
    public FmeaInfo getEntity() {
        return new FmeaInfo();
    }
    public FmeaInfoDTO getDTO() {
        return new FmeaInfoDTO();
    }

    @PostMapping({"/pageList"})
    @ApiOperation(value = "分页")
    public JsonResult<PageResult<FmeaInfoVO>> page(@RequestBody FmeaInfoDTO query){
        PageResult<FmeaInfoVO> page = getService().page(query);

        return JsonResult.ok(page);
    }

    @GetMapping("{id}")
    @ApiOperation(value = "获取信息")
    public JsonResult<FmeaInfoVO> get(@PathVariable("id") Long id){
        FmeaInfo entity = getService().getById(id);

        return JsonResult.ok(FmeaInfoConvert.INSTANCE.convert(entity));
    }

    @GetMapping("/taskId={taskId}")
    @ApiOperation(value = "获取任务执行结果")
    public JsonResult<FmeaInfoVO> getByTaskId(@PathVariable("taskId") Long taskId){
        FmeaInfo entity = getService().getByTaskId(taskId);

        return JsonResult.ok(FmeaInfoConvert.INSTANCE.convert(entity));
    }


    @PostMapping
    @ApiOperation(value = "保存")
    public JsonResult<String> save(@RequestBody FmeaInfoVO vo){
        getService().save(vo);
        return JsonResult.ok();
    }
    @PutMapping
    @ApiOperation(value = "修改")
    public JsonResult<String> update(@RequestBody FmeaInfoVO vo){
        getService().update(vo);

        return JsonResult.ok();
    }

    @DeleteMapping
    @ApiOperation(value = "删除")
    public JsonResult<String> delete(@RequestBody List<Long> idList){
        getService().delete(idList);

        return JsonResult.ok();
    }

}
